<?php
class Validation
{
    protected $required;
    
    public function isEmailValid($email){
        if($email){
            if(!preg_match("/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/", $email))
                $this->required->email = "Invalid Email";
        }
    }
    
    public function run($post_data){
        $post_data =  self::getRequiredFields($post_data);
        foreach($post_data as $key => $value){
            if(empty($value)){
               $this->required->$key = ucfirst($key) . " is required";
            }
        }
        if(isset($this->required)){
            return $this->required;
        }
        return false;
    }
    
    private function getRequiredFields($data){
        $filter_text = "-required";
        $required = array();
        foreach($data as $key => $value ){
            if(preg_match("/{$filter_text}$/",$key)){
                $required[str_replace($filter_text,'',$key)] = $value;
            }
        }
        return $required;
    }
}